home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CU Amiga Super CD-ROM 17
/
CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso
/
CUCD
/
Online
/
News
/
Thor
/
HD-Install
/
thor25_arexx.lha
/
AutoReply.br
< prev
next >
Wrap
Text File
|
1997-08-25
|
6KB
|
176 lines
/* A Thor script to generate an event in reply to */
/* an email. It should be called from SortMail3 */
VerStr = '$VER: AutoReply.br 1.2 (21.08.97) Neil Bothwick'
VerStr = subword(VerStr,2,2)
UrlStr = 'ftp://ftp.aminet.org/pub/aminet/comm/thor/AutoReplyThor.lha'
Usage = 'Usage: AutoReply.br Config MessageNo'
options results
/* ;;;Strip "'s from arg string and parse into variables */
drop Config.
parse arg CmdLine
CmdLine = compress(CmdLine,'"')
parse var CmdLine Config.Name MsgNum
if Config.Name = '?' | MsgNum = '' then call ExitMsg(Usage)
;;;
/* ;;;Load bbsread.library if necessary */
if ~show('p', 'BBSREAD') then do
address command
'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
'WaitForPort BBSREAD'
end
;;;
/* ;;;Open config file and find matching config entry */
if ~open(cfgfile,'ENV:Thor/AutoReply.cfg','r') then call ExitMsg('Failed to open configuration file')
do until eof(cfgfile) | ConfigFound = 'TRUE'
nextline = readln(cfgfile)
parse var nextline CfgName CfgVal .
CfgVal = compress(CfgVal,'"')
if upper(CfgName) = 'CONFIG' & upper(CfgVal) = upper(Config.Name) then ConfigFound = 'TRUE'
end
if eof(cfgfile) then call ExitMsg('Configuration entry for' Config.Name 'not found')
;;;
/* ;;;Read configuration details */
n = 0
do until eof(cfgfile)
nextline = readln(cfgfile)
parse var nextline CfgName '"' CfgVal '"' .
CfgVal = compress(CfgVal,'"')
if upper(CfgName) = 'ENDCONFIG' then leave
n = n+1
Config.n.Name = upper(CfgName)
Config.n.Val = CfgVal
end
Config.Count = n
do i = 1 to Config.Count
select
when Config.i.Name = 'SYSTEM' then Config.System = Config.i.Val
when Config.i.Name = 'CONFERENCE' then Config.MailConf = Config.i.Val
when Config.i.Name = 'SUBJECT' then Config.Subject = Config.i.Val
when Config.i.Name = 'QUOTEMSG' then Config.QuoteMsg = Config.i.Val
when Config.i.Name = 'QUOTESTR' then Config.QuoteStr = Config.i.Val
when Config.i.Name = 'SIGFILE' then Config.SigFile = Config.i.Val
when Config.i.Name = 'HEADFILE' then Config.HeadFile = Config.i.Val
when Config.i.Name = 'TEXTFILE' then Config.TextFile = Config.i.Val
when Config.i.Name = 'FOOTFILE' then Config.FootFile = Config.i.Val
otherwise call ExitMsg('Configuration file error')
end
end
if symbol('Config.System') ~= 'VAR' then call ExitMsg('System name not defined in config')
if symbol('Config.MailConf') ~= 'VAR' then call ExitMsg('Mail conference not defined in config')
if symbol('Config.TextFile') ~= 'VAR' then call ExitMsg('Reply text not defined in config')
if symbol('Config.QuoteStr') ~= 'VAR' then Config.QuoteStr = ''
;;;
/* ;;;Read incoming message */
address BBSREAD
drop MsgBody. MsgHead.
READBRMESSAGE bbsname '"'Config.System'"' confname '"'Config.MailConf'"' msgnr MsgNum textstem MsgBody headstem MsgHead
if RC > 0 then callExitMsg(BBSREAD.LASTERROR)
;;;
/* ;;;Create message file for reply */
UNIQUEMSGFILE bbsname '"'Config.System'"' stem MsgFile
if ~open(out,MsgFile.NAME,'w') then call ExitMsg('Unable to create message file')
;;;
/* ;;;Write headers */
headline = 'X-Generator:' VerStr
call writeln(out,headline)
headline = 'X-URL:' UrlStr
call writeln(out,headline)
if symbol('Config.HeadFile') = 'VAR' '' & exists(Config.HeadFile) then do
if ~open(headers,Config.HeadFile,'R') then call ExitMsg('Unable to open specified header file')
do until eof(headers)
headline = readln(headers)
call writeln(out,headline)
end
call close(headers)
end
if headline > '' then call writeln(out,'')
;;;
/* ;;;Quote original message above reply */
if upper(Config.QuoteMsg) = 'ABOVE' then do
do i = 1 to MsgBody.TEXT.COUNT
if length(MsgBody.TEXT.i) > 0 then call writeln(out,Config.QuoteStr||MsgBody.TEXT.i)
else call writeln(out,'')
end
end
;;;
/* ;;;Write reply */
if ~open(reply,Config.TextFile) then call ExitMsg('Unable to open reply text file')
do until eof(reply)
call writeln(out,readln(reply))
end
call close(reply)
;;;
/* ;;;Quote original message below reply */
if upper(Config.QuoteMsg) = 'BELOW' then do i = 1 to MsgBody.TEXT.COUNT
if length(MsgBody.TEXT.i) > 0 then call writeln(out,Config.QuoteStr||MsgBody.TEXT.i)
else call writeln(out,'')
end
;;;
/* ;;;Add signature */
if symbol('Config.SigFile') = 'VAR' '' & exists(Config.SigFile) then do
if ~open(sig,Config.SigFile,'R') then call ExitMsg('Unable to open signature file')
do until eof(sig)
sigline = readln(sig)
call writeln(out,sigline)
end
call close(sig)
end
;;;
/* ;;;Add footer file */
if symbol('Config.FootFile') = 'VAR' '' & exists(Config.FootFile) then do
if ~open(foot,Config.FootFile,'R') then call ExitMsg('Unable to open footer file')
do until eof(foot)
footline = readln(foot)
call writeln(out,footline)
end
call close(foot)
end
;;;
call close(out)
/* ;;;Create subject line */
ReplySubject = MsgHead.SUBJECT
select
when symbol('Config.Subject') ~= 'VAR' then do
if left(upper(ReplySubject),3) ~= 'RE:' then ReplySubject = 'Re:' ReplySubject
end
when pos('%S',upper(Config.Subject)) = 0 then ReplySubject = Config.Subject
otherwise do
InsertPos = pos('%S',upper(Config.Subject))
ReplySubject = left(Config.Subject,InsertPos-1)||ReplySubject||substr(Config.Subject,InsertPos+2)
end
end
;;;
/* ;;;Create EMail reply event */
drop EventData.
EventData.TOADDR = MsgHead.FROMADDR
EventData.SUBJECT = ReplySubject
EventData.CONFERENCE = Config.MailConf
EventData.MSGFILE = MsgFile.FILEPART
if symbol('MsgHead.FROMNAME') = 'VAR' then EventData.TONAME = MsgHead.FROMNAME
WRITEBREVENT bbsname '"'Config.System'"' event 0 stem EventData
if RC > 0 then call ExitMsg(BBSREAD.LASTERROR)
;;;
exit
/* ;;;Exit with a message */
ExitMsg:
parse arg msgstr
address command
if symbol('MsgFile.NAME') = 'VAR' then do
call close(out)
'delete >NIL:' MsgFile.NAME
end
'RequestChoice >NIL: "AutoReply.br" "'msgstr'" "Bother"'
exit
;;;